import tkinter as tk
import tkinter.font as font



#bg:背景颜色
#foreground：文字颜色

class GUI:
    def __init__(self):
        self.root = tk.Tk()
        self.root.title("演示窗口")
        self.root.geometry("800x500+1100+500")
        self.interface()


    # family：指定字体名称
    # size：指定字体大小
    # weight：指定字体的粗细程度

    def interface(self):
        self.font_1 = font.Font(family='Helvetica', size=30, weight='normal')
        self.font_2 = font.Font(family='Arial', size=15, weight='bold')

        self.label0 = tk.Button(self.root, text="文本显示",font=self.font_2,bg="lightskyblue")
        self.label0.grid(row=0, column=0)

        self.w1 = tk.Text(self.root, width=10, height=10)
        self.w1.grid(row=0,column=1)
        self.w1.insert("insert","文本输入框insert")

        self.Button0 = tk.Button(self.root, text="运行按钮/测试Entry按钮",font=self.font_2,bg="lightskyblue", command=self.event2)
        self.Button0.grid(row=0, column=2)
        self.Button1 = tk.Button(self.root, text="确定按钮", command=self.parameter("测试"))
        self.Button1.grid(row=1, column=2)
        self.Button2=tk.Button(self.root,text="退出按钮",command=self.root.destroy)
        self.Button2.grid(row=2,column=2)
        self.Button3 = tk.Button(self.root, text="checkbutton状态测试", command=self.event3,font=self.font_2,bg="lightskyblue")
        self.Button3.grid(row=3, column=3)
        self.Button3 = tk.Button(self.root, text="清除控件", command=self.event4)
        self.Button3.grid(row=4, column=3)
        self.Button4 = tk.Button(self.root, text="清除勾选",font=self.font_1,bg="pink",
 command=self.event5)
        self.Button4.grid(row=5, column=3)

        self.entry00 = tk.StringVar()
        self.entry00.set("Entry_set")

        self.Entry0 = tk.Entry(self.root,textvariable=self.entry00) #输入框
        self.Entry0.grid(row=0,column=4)

        self.v1=tk.IntVar()
        self.Checkbutton01 = tk.Checkbutton(self.root,text="复选框",command=self.Check_box,variable=self.v1)
        self.Checkbutton01.grid(row=0,column=5)

        self.Radiobutton01 = tk.Radiobutton(self.root,text="单选按钮",command=self.event)
        self.Radiobutton01.grid(row=0,column=6)

    def event(self):
        print("运行成功")

    def event2(self):
         a=self.entry00.get()
         print(a)
    def event3(self):
        b=self.v1.get()
        self.w1.insert(1.0,str(b)+"\n")#按钮事件，获取复选框状态，1表示勾选，0表示未选）

    def event4(self):#按钮事件，清除控件
        a=[self.label0,self.Entry0,self.w1]
        for i in a:
            i.grid_forget()

    def event5(self):#按钮事件，清除复选框勾选状态
        self.Checkbutton01.deselect()

    def parameter(self,data):
        print(f"获取的参数：{data}")

    def Check_box(self):
        if self.v1.get()==1:
            self.w1.insert(1.0,"勾选"+"\n")
        else:
            self.w1.insert(1.0,"未勾选"+"\n")#复选框事件



if __name__ == '__main__':
    a = GUI()
    a.root.mainloop()






